<script src="../../../resources/js-test.js"></script>
<script>
description("This test checks that we correctly update the wheel event handler count as event handlers are added and removed");

(function() {
    // Test addEventListener/removeEventListener on the document.
    var listener = function() { }

    shouldBe('internals.wheelEventHandlerCount(document)', '0');
    document.addEventListener('mousewheel', listener, true);
    shouldBe('internals.wheelEventHandlerCount(document)', '1');
    document.addEventListener('mousewheel', listener, false);
    shouldBe('internals.wheelEventHandlerCount(document)', '2');
    document.removeEventListener('mousewheel', listener, true);
    shouldBe('internals.wheelEventHandlerCount(document)', '1');

    // Try removing the capturing listener again.
    document.removeEventListener('mousewheel', listener, true);
    shouldBe('internals.wheelEventHandlerCount(document)', '1');

    document.removeEventListener('mousewheel', listener, false);
    shouldBe('internals.wheelEventHandlerCount(document)', '0');
})();

(function() {
    // Test setting onmousewheel on the document.

    shouldBe('internals.wheelEventHandlerCount(document)', '0');
    document.onmousewheel = function() { }
    shouldBe('internals.wheelEventHandlerCount(document)', '1');
    document.onmousewheel = function() { }
    shouldBe('internals.wheelEventHandlerCount(document)', '1');
    document.onmousewheel = null;
    shouldBe('internals.wheelEventHandlerCount(document)', '0');
})();

(function() {
    // Test addEventListener/removeEventListener on the window.
    var listener = function() { }

    shouldBe('internals.wheelEventHandlerCount(document)', '0');
    window.addEventListener('mousewheel', listener, true);
    shouldBe('internals.wheelEventHandlerCount(document)', '1');
    window.addEventListener('mousewheel', listener, false);
    shouldBe('internals.wheelEventHandlerCount(document)', '2');
    window.removeEventListener('mousewheel', listener, true);
    shouldBe('internals.wheelEventHandlerCount(document)', '1');

    // Try removing the capturing listener again.
    window.removeEventListener('mousewheel', listener, true);
    shouldBe('internals.wheelEventHandlerCount(document)', '1');

    window.removeEventListener('mousewheel', listener, false);
    shouldBe('internals.wheelEventHandlerCount(document)', '0');
})();

(function() {
    // Test setting onmousewheel on the window.
    shouldBe('internals.wheelEventHandlerCount(document)', '0');
    window.onmousewheel = function() { }
    shouldBe('internals.wheelEventHandlerCount(document)', '1');
    window.onmousewheel = function() { }
    shouldBe('internals.wheelEventHandlerCount(document)', '1');
    window.onmousewheel = null;
    shouldBe('internals.wheelEventHandlerCount(document)', '0');
})();

</script>
</body>
